﻿using System.Collections.Generic;

namespace SixthSense
{
    class AlertInfo
    {
        private string _Name;
        private string _Text;
        private string _Type;
        private string _Sound;
        private bool _Enable = true;
        private bool _Exact;
        private List<string> _Exclude = new List<string>();

        public AlertInfo Copy()
        {
            AlertInfo a = (AlertInfo)this.MemberwiseClone();
            a._Exclude = new List<string>();

            return a;
        }

        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        public string Text
        {
            get
            {
                return _Text;
            }
            set
            {
                _Text = value;
            }
        }

        public string Type
        {
            get
            {
                return _Type;
            }
            set
            {
                _Type = value;
            }
        }

        public string Sound
        {
            get
            {
                return _Sound;
            }
            set
            {
                _Sound = value;
            }
        }

        public bool Enable
        {
            get
            {
                return _Enable;
            }
            set
            {
                _Enable = value;
            }
        }

        public bool Exact
        {
            get
            {
                return _Exact;
            }
            set
            {
                _Exact = value;
            }
        }

        public List<string> Exclude
        {
            get
            {
                return _Exclude;
            }
            set
            {
                _Exclude = value;
            }
        }
    }

    class AlertInfoList : List<AlertInfo>
    {
        private string _SearchItem;

        public AlertInfo FindByName(string Item)
        {
            _SearchItem = Item;
            AlertInfo FoundAlert = this.Find(SearchNames);

            return FoundAlert;
        }

        private bool SearchNames(AlertInfo a)
        {
            if (a.Enable == false)
            {
                return false;
            }

            if ((a.Exact == true) && (a.Name == _SearchItem))
            {
                return true;
            }

            if ((a.Exact == false) && (_SearchItem.Contains(a.Name)))
            {
                // have a fuzzy match, check excludes
                foreach(string s in a.Exclude)
                {
                    if (_SearchItem.Contains(s))
                    {
                        return false;
                    }
                }
                return true;
            }

            return false;
        }

        public AlertInfoList FindAllByType(string Type)
        {
            List<AlertInfo> all = new List<AlertInfo>();

            all = this.FindAll(o => o.Type == Type);

            // im sure there is a better way to do this
            AlertInfoList ail = new AlertInfoList();

            foreach (AlertInfo a in all)
            {
                ail.Add(a);
            }

            return ail;
        }

        public AlertInfoList Copy()
        {
            AlertInfoList a = (AlertInfoList)this.MemberwiseClone();

            return a;
        }
    }
}
